﻿package frEngine.shader.filters.fragmentFilters.extra
{
    import __AS3__.vec.*;
    import flash.geom.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.*;

    public class PlayerBackLightFilter extends FilterBase
    {
        public var lightAmbient:Vector.<Number>;
        public var lightDiffuse:Vector.<Number>;
        public var lightDir:Vector.<Number>;
        public var cameraPos:Vector.<Number>;

        public function PlayerBackLightFilter()
        {
            this.lightAmbient = this.Vector.<Number>([0.9, 0.9, 0.9, 1]);
            this.lightDiffuse = this.Vector.<Number>([32 / 255, 26 / 255, 101 / 255, 1]);
            this.lightDir = this.Vector.<Number>([0, 0, 1, 100]);
            this.cameraPos = this.Vector.<Number>([0, 0, -1000, 1]);
            super(FilterType.PlayerBackLightFilter, FilterPriority.PlayerBackLightFilter, null);
            this.calculate();
            return;
        }// end function

        override public function setRegisterParams(param1:Program3dRegisterInstance) : void
        {
            param1.getParamByName("{lightAmbient}", false).value = this.lightAmbient;
            param1.getParamByName("{lightDiffuse}", false).value = this.lightDiffuse;
            param1.getParamByName("{lightDir}", false).value = this.lightDir;
            param1.getParamByName("{CamPos}", false).value = this.cameraPos;
            return;
        }// end function

        public function calculate() : void
        {
            var _loc_1:* = new Vector3D(0, 0, 1, 0);
            var _loc_2:* = new Matrix3D();
            _loc_2.appendRotation(-100, Vector3D.Y_AXIS);
            _loc_1 = _loc_2.transformVector(_loc_1);
            this.lightDir[0] = _loc_1.x;
            this.lightDir[1] = _loc_1.y;
            this.lightDir[2] = _loc_1.z;
            return;
        }// end function

        override public function get programeId() : String
        {
            return "PlayerBackLightFilter";
        }// end function

        override public function createVertexCode(param1:Program3dRegisterInstance, param2:int) : String
        {
            var _loc_3:Array = [new ToBuilderInfo("vf1", "{V_localPos}", false, 1)];
            var _loc_4:String = "mov\t\tvf1\t\t\t\t\t\t{output} \n";
            return param1.toBuild(_loc_4, _loc_3);
        }// end function

        override public function createFragmentColor(param1:Program3dRegisterInstance, param2:Boolean) : String
        {
            var _loc_3:* = new Array();
            _loc_3.push(new ToBuilderInfo("fc1", "{lightAmbient}", false, 1, this.lightAmbient));
            _loc_3.push(new ToBuilderInfo("fc2", "{lightDiffuse}", false, 1, this.lightDiffuse));
            _loc_3.push(new ToBuilderInfo("fc9", "{CamPos}", false, 1, this.cameraPos));
            _loc_3.push(new ToBuilderInfo("fc10", "{lightDir}", false, 1, this.lightDir));
            _loc_3.push(new ToBuilderInfo("fm0", FilterName.worldView, true, 4));
            var _loc_4:String = "";
            _loc_4 = _loc_4 + ("mov\t\tft0,\t\t\t\t\t\t{lightAmbient} \n" + "mov \t\tft1, \t\t\t\t\t\t{lightDir}, \t\t\t\t\t\t\t\t\t \n" + "nrm\t\tft1.xyz,\t\t\t\tft1.xyz \n" + "m33 \t\tft2.xyz,\t\t\t\t{vnormal},\t\t\t\t\t\t\t\t\tfm0 \t\t\n" + "nrm \t\tft2.xyz, \t\t\t\tft2.xyz\t\n" + "dp3 \t\tft4.x, \t\t\t\t\tft1.xyz, \t\t\t\t\t\t\t\t\tft2.xyz \t\n" + "neg \t\tft4.x, \t\t\t\t\tft4.x \t\t\t\t\t\t\t\t\t\t\t\t\t\n" + "sat \t\tft3.x, \t\t\t\t\tft4.x  \n" + "add\t\tft4.x,\t\t\t\t\t\t{lightDir}.w,\t\t\t\t\t\t\t{V_localPos}.y\n" + "div\t\tft4.x,\t\t\t\t\t\t{lightDir}.w,\t\t\t\t\t\t\tft4.x\n" + "mul\t\tft3.x,\t\t\t\t\t\tft3.x,\t\t\t\t\t\t\t\t\tft4.x\n" + "mul\t\tft3,\t\t\t\t\t\tft3.x,\t\t\t\t\t\t\t\t\t\t\t\t{lightDiffuse}\n" + "mul \t\t{output}, \t\t\t\tft0,  \t\t\t\t\t\t\t\t\t\t\t\t{output} \n" + "add\t\t{output}.xyz,\t\t\tft3.xyz,\t\t\t\t\t\t\t\t\t\t\t{output}.xyz \n");
            return param1.toBuild(_loc_4, _loc_3);
        }// end function

    }
}
